package com.baizhi.action;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpSession;
import java.io.ByteArrayInputStream;

public class CaptchaAction {

    private ByteArrayInputStream stream;

    public String captchaCreate(){
        CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 50, 4, 4);
        stream = new ByteArrayInputStream(captcha.getImageBytes());

        HttpSession session = ServletActionContext.getRequest().getSession();
        session.setAttribute("captcha",captcha);
        return "captchaCreate";
    }

    public String captchaRegist(){
        CircleCaptcha captchaRegist = CaptchaUtil.createCircleCaptcha(200, 50, 4, 4);
        stream = new ByteArrayInputStream(captchaRegist.getImageBytes());

        HttpSession session = ServletActionContext.getRequest().getSession();
        session.setAttribute("captchaRegist",captchaRegist);
        return "captchaRegist";
    }

    public ByteArrayInputStream getStream() {
        return stream;
    }

    public void setStream(ByteArrayInputStream stream) {
        this.stream = stream;
    }
}
